<%@ page import="java.net.URL" %>
<%@ page import="java.net.URLClassLoader" %>
<%@ page import="java.util.*" %>
<%@ page import="java.lang.reflect.TypeVariable" %>
<%@ page import="java.lang.reflect.Type" %>
<%@ page import="java.lang.reflect.ParameterizedType" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head><title>Simple jsp page</title></head>
<%!
    private static boolean isWindows = System.getProperty ("os.name").toLowerCase ().indexOf ("windows") >= 0;
    private static char c = isWindows ? ';' : ':';
    private boolean isResin;

    private void appendClassLoader (ClassLoader loader, Set<String> set) {
        if (loader instanceof URLClassLoader) {
            URLClassLoader ucl = (URLClassLoader) loader;
            for (URL url : ucl.getURLs ()) {
                String path = url.getPath ();
                if (path.startsWith ("file:")) path = path.substring (5);
                if (isWindows && path.charAt (0) == '/') path = path.substring (1);
                if (path.endsWith ("!/")) path = path.substring (0, path.length () - 2);
                path = path.replace ("%20", " ");
                set.add (path);
            }
        }
        if (loader.getParent () != null) appendClassLoader (loader.getParent (), set);
    }
%>
<body>
<h1>Application</h1>
<table border=1>
    <tr>
        <th>Key</th><th>Value</th><th>Type</th>
    </tr>
<%
    isResin = false;
    for (java.util.Enumeration e = application.getAttributeNames (); e.hasMoreElements ();) {
        String key = (String) e.nextElement ();
        if ("caucho.authenticator".equalsIgnoreCase (key)) isResin = true;
        Object value = application.getAttribute (key);
%>
    <tr>
        <td><%= key%></td><td><%= value%></td><td><%= value == null ? "" : value.getClass ().getName ()%></td>
    </tr>
<%  }
%>
</table>
<h1>System Info</h1>
OS: <%= System.getProperty ("os.name") %><br/>
<%  Properties props = System.getProperties ();%>
<table border="1">
    <tr><th>Key</th><th>Value</th></tr>
<%  for (String name : props.stringPropertyNames ()) {%>
    <tr>
        <td><%= name%></td>
        <td><%= props.getProperty(name)%></td>
    </tr>
<%}%>
</table>
<%
    Map<String, String> env = System.getenv ();
%>
<table border="1">
    <tr>
        <th>Key</th><th>Value</th>
    </tr>
<% for (String key : env.keySet ()) {%>
    <tr>
        <td><%= key%></td><td><%= env.get(key)%></td>
    </tr>
<%  }%>
</table>
<%
    ClassLoader loader = getClass ().getClassLoader ();
    Set<String> set = new TreeSet<String> ();
    appendClassLoader (loader, set);
    for (String url : set)
        out.println (url + "<br/>");
%>
<%
    request.getRemoteAddr ();
%>
<hr/>

</body>
</html>